﻿@using LanDBom.Models
@using LanDBom.Resources
@{
    ViewBag.Title = "Home Page";
}
@section styles{
    <style>
        .JKKNF {
            width: 100%;
        }

            .JKKNF td, .JKKNF th {
                width: 200px;
                word-break: keep-all;
                white-space: nowrap;
            }

                .JKKNF td:nth-child(1), .JKKNF th:nth-child(1) {
                    width: 50px;
                }
    </style>
}
<div>
    <div id="wid">
        <form class="row padtop col-12">
            <fieldset class="boun">
                <legend class="len">@Resource.String155</legend>
                <div class="row">
                    <div class="col-2">创建日期从：</div>
                    <div class="col-2"><input type="date" id="qssj" class="ziduan" /></div>
                    <div class="col-2">到:</div>
                    <div class="col-2"><input type="date" id="jssj" class="ziduan" /></div>
                    <div class="col-2">截止日期</div>
                    <div class="col-2"><input type="date" id="jzrrq" class="ziduan" /></div>
                    <div class="col-2">申请单号</div>
                    <div class="col-2"><input type="text" id="bian" class="ziduan" /></div>
                    <div class="col-2">@Resource.String375</div>
                    <div class="col-2"><input type="text" id="BB_SQ_xmmc" class="ziduan" /></div>
                    <div class="col-2">@Resource.String376</div>
                    <div class="col-2"><input type="text" id="BB_SQ_khmc" class="ziduan" /></div>
                    <div class="col-2">关键词搜索</div>
                    <div class="col-2"><input type="text" id="BB_SQ_gjz" class="ziduan" /></div>
                    <div class="col-2">项目状态</div>
                    <div class="col-2">
                        <select id="xmlx" class="ziduan">
                            <option value="0">请选择</option>
                            <option value="WON Opportunities">WON Opportunities</option>
                            <option value="OPEN Opportunities">OPEN Opportunities</option>
                            <option value="LOST Opportunities">LOST Opportunities</option>
                        </select>
                    </div>
                    <div class="col-2">项目进度</div>
                    <div class="col-2">
                        <select id="xmjsbjs" class="ziduan">
                            <option value="0">请选择</option>
                            <option value="1">项目结束</option>
                            <option value="2">项目执行中</option>
                        </select>
                    </div>
                    <div class="col-2">项目步骤</div>
                    <div class="col-2">
                        <select id="xmjd" class="ziduan">
                            <option value="0">请选择</option>
                            <option value="1_1">等待业务提交到设计主管</option>
                            <option value="1_2">等待设计主管分配</option>
                            <option value="1_3">等待设计提交设计图</option>
                            <option value="1_4">等待业务审核</option>
                            <option value="2">BOM重置</option>
                            <option value="3">工艺配置</option>
                            <option value="4">物料询价</option>
                            <option value="5">物料核价</option>
                            <option value="8">核价审批</option>
                            <option value="6">对外报价</option>
                            <option value="9">报价审批</option>
                            <option value="7">生成报价单</option>
                        </select>
                    </div>
                    <div class="col-2">项目负责人</div>
                    <div class="col-2">
                        <select id="MRRY" class="ziduan">
                            <option value="">无</option>
                            @foreach (Dengli item in ViewBag.MRRRY)
                            {
                                if (!@item.DE_nae.Contains("业务"))
                                {
                                    <option value="@item.DE_nae">@item.DE_nae</option>
                                }
                            }
                        </select>
                    </div>
                    <div class="col-2">是否设计</div>
                    <div class="col-2">
                        <select id="Sheji" class="ziduan">
                            <option value="">无</option>
                            <option value="N">无设计</option>
                            <option value="S">纯设计</option>
                            <option value="Y">设计+报价</option>
                        </select>
                    </div>
                    <div class="col-2 btn-sm  btn-warning" id="BB_WT_cxssss" style="text-align:center">@Resource.String374</div>
                </div>
            </fieldset>
        </form>

        <div class="div_A" style="width:100%;height:600px;">
            <table class="JKKNF table" style="width:100%;" id="UNHT">
                <thead>
                    <tr style="text-align-last:left;width:100%">
                        <th scope="col">@Resource.String156</th>
                        <th scope="col">@Resource.String157</th>
                        <th scope="col">@Resource.String158</th>
                        <th scope="col">@Resource.String159</th>
                        <th scope="col">@Resource.String160</th>
                        <th scope="col">@Resource.String161</th>
                        <th scope="col">项目进度</th>
                        <th scope="col">项目进度条</th>
                        <th scope="col">@Resource.String162</th>
                        <th scope="col" style="display:none"></th>
                    </tr>
                </thead>
                <tbody id="BUtain2">
                </tbody>
            </table>
            @*<div style="height:600px; overflow-y:scroll;overflow-x:hidden">
                    <table class="table JKKNF" style="text-align-last:left" id="UNHT">
                        <thead id="BUtain">

                        </thead>
                    </table>
                </div>*@
        </div>
    </div>
    <div style="display: flex; justify-content: space-between;">
        <span>共<span id="Hangs"></span> 行</span>
        @using (Html.BeginForm("Cliview", "Application", FormMethod.Post))
        {<nav aria-label="Page navigation example" class="row" style="margin-right:50px;">
                <ul class="pagination">
                </ul>
                共<span id="komdr"></span>页
            </nav>
        }
    </div>
</div>

@section scripts{
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script>
        $(function () {
            $("#li9").css({ "color": "black", "background-color": "white" })

            var JJNMK = $("#Login_N").text()
            $("#MRRY").val(JJNMK)
        })
        chuasunji()
        function chuasunji() {
            var bcunJls = {
                BO_name: $("#Login_N").text(),
                BO_DJM: "ZL",
            }
            console.log(bcunJls)
            $.ajax({
                url: '/Home/BaoCunTJ',
                type: 'POST',
                data: { "bcun": bcunJls, "state": 1 },
                success: function (date) {
                    console.log(date.length - 1)
                    $.each(date, function (i, item) {
                        $("#" + item.BO_ZDID + "").val(item.BO_VAL)
                        if (i == (date.length - 1)) {
                            console.log("AAAAAA")
                            Hnaghshu()
                        }
                    })
                },
                error: function () {
                    alert("错误 请重试！")
                }
            })
        }
        function Hnaghshu() {
            var BB_SQ_xmmc = $("#BB_SQ_xmmc").val()
            var BB_SQ_khmc = $("#BB_SQ_khmc").val()
            var BB_SQ_sqrq = $("#BB_SQ_sqrq").val()
            var BB_SQ_gjz = $("#BB_SQ_gjz").val()
            var qssj = $("#qssj").val()
            var jssj = $("#jssj").val()
            var bian = $("#bian").val()
            var xmlx = $("#xmlx").val()
            var xmjd = $("#xmjd").val()
            var jzrq = $("#jzrrq").val()
            var xmjs = $("#xmjsbjs").val()
            var MRRY = $("#MRRY").val()
            var Sheji = $("#Sheji").val()
            $.ajax({
                url: '/Home/Index',
                type: 'POST',
                data: { "BB_SQ_xmmc": BB_SQ_xmmc, "BB_SQ_khmc": BB_SQ_khmc, "BB_SQ_gjz": BB_SQ_gjz, "states": 12, "qssj": qssj, "jssj": jssj, "danhao": bian, "xmlx": xmlx, "xmjd": xmjd, "jzrq": jzrq, "xmjs": xmjs, "MRRY": MRRY, "Sheji": Sheji },
                success: function (date) {
                    console.log(date, Math.floor(HJ / 10) + 1)
                    var HJ = date * 1
                    var HNH = HJ / 10 < 1 ? 1 : Math.floor( HJ / 10) + 1
                    $("#Hangs").text(HJ)
                    $("#komdr").text(HNH)
                }, error: function () {
                    alert("系统错误")
                }
            })
        }
        //点击申请单号判断当前步骤进行跳转
        $(function () {
            $(document).on("mouseenter", ".XuanZ", function () {
                $(this).css({ "background-color": "#90898080" })
                $(this).siblings().css({ "background": "none" })
                $(this).parent().siblings().children().css({ "background": "none" })
            })
            $(document).on("click", "#Dan", function (e) {
                var B_dan = $(e.target).text();
                var B_dount = $(e.target).next().text();
                var B_zhang = $(e.target).parent().children().eq(11).text();
                var ID = $(e.target).parent().children().eq(1).text();
                //2:bom 3:工艺 4:询价 6：报价
                var bm = $("#Login_bm").text()
                var sf = $("#Login_sf").text()
                var name = $("#Login_N").text()
                //if (B_dount == -99) {
                //    window.location.href = "/Contracts/Inspect_Contracts"
                //}
                window.location.href = "/Application/Application_2?Name=" + B_dan;


            })
        })
        //查询功能
        $(function () {
            skonf()
            $(document).on("click", "#BB_WT_cx", function (ad) {
                if (confirm("是否删除该行")) {
                    var bian = $(ad.target).parent().parent().children().first().next().next().text()
                    $.ajax({
                        url: '/Home/Index',
                        type: 'POST',
                        data: { "AP_bian": bian, "states": 4 },
                        success: function (date) {
                            alert(date)
                            location.reload(true)
                        }, error: function () {
                            alert("系统错误")
                        }
                    })
                }
            })
            $("#BB_WT_cxssss").click(function () {
                skonf()
            })
            function Baoisn() {
                var bcunJls = []
                $(".ziduan").each(function (i, item) {
                    var name = $("#Login_N").text()
                    var DJM = "ZL"
                    bcunJls.push({
                        BO_name: name,
                        BO_DJM: DJM,
                        BO_ZDID: $(item).attr("id"),
                        BO_VAL: $(item).val(),
                    })
                })
                console.log(bcunJls)
                $.ajax({
                    url: '/Home/BaoCunTJ',
                    type: 'POST',
                    data: { "bcunJls": bcunJls, "state":0},
                    success: function (date) {
                        console.log(date)
                    },
                    error: function () {
                        alert("错误 请重试！")
                    }
                })
            }
            function skonf() {
                var BB_SQ_xmmc = $("#BB_SQ_xmmc").val()
                var BB_SQ_khmc = $("#BB_SQ_khmc").val()
                var BB_SQ_sqrq = $("#BB_SQ_sqrq").val()
                var BB_SQ_gjz = $("#BB_SQ_gjz").val()
                var qssj = $("#qssj").val()
                var jssj = $("#jssj").val()
                var bian = $("#bian").val()
                var xmlx = $("#xmlx").val()
                var xmjd = $("#xmjd").val()
                var jzrq = $("#jzrrq").val()
                var xmjs = $("#xmjsbjs").val()
                var MRRY = $("#MRRY").val()
                var Sheji = $("#Sheji").val()
                $.ajax({
                    url: '/Home/Index',
                    type: 'POST',
                    data: { "BB_SQ_xmmc": BB_SQ_xmmc, "BB_SQ_khmc": BB_SQ_khmc, "BB_SQ_gjz": BB_SQ_gjz, "states": 1, "qssj": qssj, "jssj": jssj, "danhao": bian, "xmlx": xmlx, "xmjd": xmjd, "jzrq": jzrq, "xmjs": xmjs, "MRRY": MRRY, "Sheji": Sheji },
                    success: function (date) {
                        //console.log(date)
                        Hnaghshu()
                        Baoisn()
                        fenye("1")
                        createRow(date);
                    },
                    error: function () {
                        alert("错误 请重试！")
                    }
                })
            }

            function fenye(a) {
                var hjin = a * 1
                var shunddd = $("#komdr").text() * 1
                $(".pagination li").remove()
                var $ul = ""
                $ul += (`<li class="page-item"><span class="page-link shiyong"><<<</span></li>`)
                for (var i = 1; i <= shunddd; i++) {
                    if (shunddd < 4) {
                        if (i < 5) {
                            if (hjin == i) {
                                $ul += "<li class='page-item'><span class='page-link shiyong' id='shiyongll' style='background-color:#c4ded9'>" + i + "</span></li>";
                            } else {
                                $ul += "<li class='page-item'><span class='page-link shiyong'>" + i + "</span></li>";
                            }
                        } else {
                            $ul += "<li class='page-item'><span class='page-link'>.....</span></li>";
                            break
                        }
                    }
                    if (shunddd >= 4) {
                        if (i < (hjin - 2) || i >= (hjin + 2)) {
                            continue
                        }
                        if (i > (hjin - 2) && i < (hjin + 2)) {

                            if (hjin == i) {
                                $ul += "<li class='page-item'><span class='page-link shiyong' id='shiyongll' style='background-color:#c4ded9'>" + i + "</span></li>";
                            } else {
                                $ul += "<li class='page-item'><span class='page-link shiyong'>" + i + "</span></li>";
                            }
                        } else {
                            $ul += "<li class='page-item'><span class='page-link'>.....</span></li>";
                        }
                    }
                }
                $ul += (`<li class="page-item"><span class="page-link shiyong">>>></span></li>`);
                $(".pagination").append($ul)
            }
            $(document).on("click", ".shiyong", function () {
                var shunddd = $("#komdr").text()*1
                var sjind = $(this).text()
                var BB_SQ_xmmc = $("#BB_SQ_xmmc").val()
                var BB_SQ_khmc = $("#BB_SQ_khmc").val()
                var BB_SQ_sqrq = $("#BB_SQ_sqrq").val()
                var BB_SQ_gjz = $("#BB_SQ_gjz").val()
                var qssj = $("#qssj").val()
                var jssj = $("#jssj").val()
                var bian = $("#bian").val()
                var xmlx = $("#xmlx").val()
                var xmjd = $("#xmjd").val()
                var jzrq = $("#jzrrq").val()
                var xmjs = $("#xmjsbjs").val()
                var MRRY = $("#MRRY").val()
                var Sheji = $("#Sheji").val()
                sjind = sjind == "<<<" ? "1" : sjind == ">>>" ? shunddd : sjind * 1
                fenye(sjind)
                $.ajax({
                    url: '/Home/Index',
                    type: 'POST',
                    data: { "BB_SQ_xmmc": BB_SQ_xmmc, "BB_SQ_khmc": BB_SQ_khmc, "BB_SQ_gjz": BB_SQ_gjz, "states": 1, "qssj": qssj, "jssj": jssj, "danhao": bian, "xmlx": xmlx, "xmjd": xmjd, "shund": sjind - 1, "jzrq": jzrq, "xmjs": xmjs, "MRRY": MRRY, "Sheji": Sheji },
                    success: function (date) {
                        Hnaghshu()
                        createRow(date);
                    },
                    error: function () {
                        alert("错误 请重试！")
                    }
                })
            })
            function sjnn() {
                var sjinf = $("#shiyongll").text()*1-1
                var len = $('#UNHT tbody tr').length;
                for (var i = 0; i < len; i++) {
                    //获取当前行的值
                    var shuan = $('#UNHT tbody tr:eq(' + i + ') td:nth-child(4)').text() * 1;
                    var zhang = $('#UNHT tbody tr:eq(' + i + ') td:nth-child(15)').text() * 1;
                    shuan = shuan == -99 ? zhang : shuan;
                    var yans = $('#UNHT tbody tr:eq(' + i + ') td:nth-child(17)').text();
                    if (yans!="0") {
                        $('#UNHT tbody tr:eq(' + i + ') td:nth-child(8)').css({ "color": "red" });
                    }
                    $('#UNHT tbody tr:eq(' + i + ') td:nth-last-child(6) div span').remove();
                    for (var j = 0; j < zhang; j++) {
                        var $li ="";
                        if (j < shuan) {
                             $li = $(`<span style="height:13px;width:13px;background-color:deepskyblue;margin: 4px;"></span>   `);
                        } else {
                            $li = $(`<span style="height:13px;width:13px;background-color:#dddddd;margin: 4px;"></span>   `);
                        }
                        $('#UNHT tbody tr:eq(' + i + ') td:nth-last-child(6) div').append($li);
                    }
                    $('#UNHT tbody tr:eq(' + i + ') td:first').text(sjinf*10+i + 1);
                }
            }
            function createRow(date) {
                $("#BUtain2 tr").remove();
                $.each(date, function (i, item) {
                     var $tr =(`<tr class="XuanZ" style="max-height:50px">
                                        <td ></td>
                                        <td style="display:none">${item.App_id}</td>
                                        <td id="Dan" style="color:#2a6bcc;">${item.AP_bian}</td>
                                        <td class="sr-only C_jin" style="display:none" id="poi">${item.App_bu}</td>
                                        <td >${item.App_Kehu}</td>
                                        <td >${item.APP_name}</td>
                                        <td >${item.App_qishi}</td>
                                        <td >${item.App_JTime}</td>
                                        <td >${item.APP_liy}</td>
                                        <td >${item.App_xmzt}</td>
                                        <td style="display:none" id="shun">${item.APP_fenL}</td>
                                        <td ><div style="display:flex"></div></td>
                                        <td style="display:none"></td>
                                        @if (MyAuthentication.IsLogin())
                                        {
                                            if (MyAuthentication.GetUsers().DE_quan== "管理员"||MyAuthentication.GetUsers().DE_zhiji>=3)
                                            {
                                                <td ><button id="BB_WT_cx" style="border:0;color:red;background:none">删除</button></td>
                                            }
                                            else
                                            {
                                                <td style="display:none"></td>
                                            }
                                        }
                                        <td style="display:none" id="zhand">${item.App_zhand}</td>
                                        <td style="display:none" id="zhand">${item.AP_ren}</td>
                                        <td style="display:none" id="zhand">${item.App_tuzhi}</td>
                                </tr>`);
                    $("#BUtain2").append($tr)
                })
                sjnn()
            }
        })

    </script>
}